package cn.wolfcode.trip.admin.Controller;


import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyQuery;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 大攻略资源控制器
 */
@Controller
@RequestMapping("/strategy")
public class StrategyController {

    @Autowired
    private IStrategyService strategyService;

    /**
     * 查出所有的大攻略
     * 分页
     * 高查:关键字
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String query(@ModelAttribute("qo") StrategyQuery qo, Model model){
        PageInfo<Strategy> pageInfo= strategyService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "/strategy/list";
    }

    /**
     * 保存修改大攻略
     * @param strategy
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(Strategy strategy){
        JSONResult jsonResult =new JSONResult();

        try {
            strategyService.saveOrUpdate(strategy);
        } catch (Exception e) {
            jsonResult.mark("操作失败,请稍后再试");
            e.printStackTrace();
        }

        return jsonResult;
    }
}
